/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.acq.web.dataview;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.acq.entity.dataview.AcqDataview;
import com.thinkgem.jeesite.modules.acq.service.dataview.AcqDataviewService;

/**
 * 村介绍Controller
 * @author lj
 * @version 2018-09-14
 */
@Controller
@RequestMapping(value = "${adminPath}/acq/dataview/acqDataview")
public class AcqDataviewController extends BaseController {

	@Autowired
	private AcqDataviewService acqDataviewService;
	
	@ModelAttribute
	public AcqDataview get(@RequestParam(required=false) String id) {
		AcqDataview entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = acqDataviewService.get(id);
		}
		if (entity == null){
			entity = new AcqDataview();
		}
		return entity;
	}
	
	@RequiresPermissions("acq:dataview:acqDataview:view")
	@RequestMapping(value = {"list", ""})
	public String list(AcqDataview acqDataview, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AcqDataview> page = acqDataviewService.findPage(new Page<AcqDataview>(request, response), acqDataview); 
		model.addAttribute("page", page);
		return "modules/acq/dataview/acqDataviewList";
	}

	@RequiresPermissions("acq:dataview:acqDataview:view")
	@RequestMapping(value = "form")
	public String form(AcqDataview acqDataview, Model model) {
		model.addAttribute("acqDataview", acqDataview);
		return "modules/acq/dataview/acqDataviewForm";
	}

	@RequiresPermissions("acq:dataview:acqDataview:edit")
	@RequestMapping(value = "save")
	public String save(AcqDataview acqDataview, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, acqDataview)){
			return form(acqDataview, model);
		}
		acqDataviewService.save(acqDataview);
		addMessage(redirectAttributes, "保存村介绍成功");
		return "redirect:"+Global.getAdminPath()+"/acq/dataview/acqDataview/?repage";
	}
	
	@RequiresPermissions("acq:dataview:acqDataview:edit")
	@RequestMapping(value = "delete")
	public String delete(AcqDataview acqDataview, RedirectAttributes redirectAttributes) {
		acqDataviewService.delete(acqDataview);
		addMessage(redirectAttributes, "删除村介绍成功");
		return "redirect:"+Global.getAdminPath()+"/acq/dataview/acqDataview/?repage";
	}

}